package com.ruoyi.web.controller.pet;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pet.domain.PetFinance;
import com.ruoyi.pet.service.IPetFinanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 费用记录Controller
 * 
 * @author 木有枝
 * @date 2025-04-13
 */
@RestController
@RequestMapping("/pet/finance")
public class PetFinanceController extends BaseController
{
    @Autowired
    private IPetFinanceService petFinanceService;

    /**
     * 查询费用记录列表
     */
    @PreAuthorize("@ss.hasPermi('pet:finance:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetFinance petFinance)
    {
        startPage();
        List<PetFinance> list = petFinanceService.selectPetFinanceList(petFinance);
        return getDataTable(list);
    }

    /**
     * 导出费用记录列表
     */
    @PreAuthorize("@ss.hasPermi('pet:finance:export')")
    @Log(title = "费用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetFinance petFinance)
    {
        List<PetFinance> list = petFinanceService.selectPetFinanceList(petFinance);
        ExcelUtil<PetFinance> util = new ExcelUtil<PetFinance>(PetFinance.class);
        util.exportExcel(response, list, "费用记录数据");
    }

    /**
     * 获取费用记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('pet:finance:query')")
    @GetMapping(value = "/{financeId}")
    public AjaxResult getInfo(@PathVariable("financeId") Long financeId)
    {
        return success(petFinanceService.selectPetFinanceByFinanceId(financeId));
    }

    /**
     * 新增费用记录
     */
    @PreAuthorize("@ss.hasPermi('pet:finance:add')")
    @Log(title = "费用记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetFinance petFinance)
    {
        return toAjax(petFinanceService.insertPetFinance(petFinance));
    }

    /**
     * 修改费用记录
     */
    @PreAuthorize("@ss.hasPermi('pet:finance:edit')")
    @Log(title = "费用记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetFinance petFinance)
    {
        return toAjax(petFinanceService.updatePetFinance(petFinance));
    }

    /**
     * 删除费用记录
     */
    @PreAuthorize("@ss.hasPermi('pet:finance:remove')")
    @Log(title = "费用记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{financeIds}")
    public AjaxResult remove(@PathVariable Long[] financeIds)
    {
        return toAjax(petFinanceService.deletePetFinanceByFinanceIds(financeIds));
    }
}
